package com.example.wto.myapplication;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wto on 4/14/2017.
 */

public class Teacher implements ConvertToJsonObject
{
    private List<DayOfWeek> weekList=null;//星期7天
    private String id;//教师id
    private String name;//教师姓名
    private String s_id;//学期
    public Teacher()
    {
        weekList=new ArrayList<DayOfWeek>();
    }

    public Teacher(String s_id,String id,String name)
    {
        this.id = id;
        this.name = name;
        this.s_id = s_id;
        weekList=new ArrayList<DayOfWeek>();
    }


    public Teacher(String id, String name)
    {

        this.id = id;
        this.name = name;
        weekList=new ArrayList<DayOfWeek>();
    }

    public Teacher( String id, String name, List<DayOfWeek> weekList)
    {
        this.weekList = weekList;
        this.id = id;
        this.name = name;
        weekList=new ArrayList<DayOfWeek>();
    }
    public String getS_id()
    {
        return s_id;
    }

    public void setS_id(String s_id)
    {
        this.s_id = s_id;
    }

    public List<DayOfWeek> getWeekList()
    {
        return weekList;
    }

    public void setWeekList(List<DayOfWeek> weekList)
    {
        this.weekList = weekList;
    }

    public String getId()
    {
        return id;
    }

    public void setId(String id)
    {
        this.id = id;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    @Override
    public String toJsonObject()
    {
        JSONObject jsonObject=new JSONObject();
        JSONArray jsonArray=new JSONArray();
        try
        {
            jsonObject.put("id",id);
            jsonObject.put("name",name);
            DayOfWeek weekDay=null;
            for(int i=0;i<weekList.size();i++)
            {
                weekDay=weekList.get(i);
                JSONObject jso=new JSONObject();
                jso.put("weekName",weekDay.getWeekName());
                JSONArray jsonArrayCourse = new JSONArray();
                List<Course> courseList=weekDay.getCourseList();
                for(int j=0;j<courseList.size();j++)
                {
                	jsonArrayCourse.put(courseList.get(j).getCourseName());
                }
                jso.put("course", jsonArrayCourse);
                jsonArray.put(jso);
            }
            jsonObject.put("courses",jsonArray);
        } catch (JSONException e)
        {
            e.printStackTrace();
        }
        return jsonObject.toString();
    }
}
